﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class Album : LastfmModelBase, IHasFiveImages
    {
        public Album()
        {
            this.Name = string.Empty;
            this.Artist = string.Empty;
            this.Id = 0;
            this.Mbid = string.Empty;
            this.Url = string.Empty;
            this.ReleaseDate = DateTime.MinValue;
            this.ImageSmall = string.Empty;
            this.ImageMedium = string.Empty;
            this.ImageLarge = string.Empty;
            this.ImageExtralarge = string.Empty;
            this.ImageMega = string.Empty;
            this.Listeners = 0;
            this.PlayCount = 0;
            this.Tracks = new List<AlbumTrack>();
            this.TopTags = new List<TopTag>();
            this.Wiki = new Wiki();
        }

        public Album(XmlNode albumNode)
            : this()
        {
            if (albumNode == null) return;
            this.InitializeFromXmlNode(albumNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Name = node.GetChildValue("name");
            this.Artist = node.GetChildValue("artist");
            this.Id = node.GetChildValue("id").ToInteger();
            this.Mbid = node.GetChildValue("mbid");
            this.Url = node.GetChildValue("url");
            this.ReleaseDate = node.GetChildValue("releasedate").ToDateTime();
            this.ImageSmall = node.GetChildValueWithSpecialAtrribute("image", "size", "small");
            this.ImageMedium = node.GetChildValueWithSpecialAtrribute("image", "size", "medium");
            this.ImageLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "large");
            this.ImageExtralarge = node.GetChildValueWithSpecialAtrribute("image", "size", "extralarge");
            this.ImageMega = node.GetChildValueWithSpecialAtrribute("image", "size", "mega");
            this.Listeners = node.GetChildValue("listeners").ToInteger();
            this.PlayCount = node.GetChildValue("playcount").ToInteger();
            this.Tracks = LastfmModelBase.GetList<AlbumTrack>(node.GetChild("tracks"), "track");
            this.TopTags = LastfmModelBase.GetList<TopTag>(node.GetChild("toptags"), "tag");
            this.Wiki = new Wiki(node.GetChild("wiki"));
        }

        public string Name
        {
            get;
            set;
        }

        public string Artist
        {
            get;
            set;
        }

        public int Id
        {
            get;
            set;
        }

        public string Mbid
        {
            get;
            set;
        }

        public string Url
        {
            get;
            set;
        }

        public DateTime ReleaseDate
        {
            get;
            set;
        }

        public string ImageSmall
        {
            get;
            set;
        }

        public string ImageMedium
        {
            get;
            set;
        }

        public string ImageLarge
        {
            get;
            set;
        }

        public string ImageExtralarge
        {
            get;
            set;
        }

        public string ImageMega
        {
            get;
            set;
        }

        public int Listeners
        {
            get;
            set;
        }

        public int PlayCount
        {
            get;
            set;
        }

        public IList<AlbumTrack> Tracks
        {
            get;
            set;
        }

        public IList<TopTag> TopTags
        {
            get;
            set;
        }

        public Wiki Wiki
        {
            get;
            set;
        }
    }
}
